<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <meta charset="utf-8">
    <head th:include="common/base_include :: header"></head>
    <body class="gray-bg">
        <div class="wrapper wrapper-content ">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-body">
                        <div id="exampleToolbar" role="group" class="t-bar">
                            <button shiro:hasPermission="sys:menu:add" type="button"
                                    class="btn btn-primary" title="在根节点下添加菜单" onclick="add('0')">
                                <i class="fa fa-plus" aria-hidden="true"></i>添加
                            </button>
                            <button shiro:hasPermission="sys:menu:batchRemove" type="button"
                                    class="btn btn-danger" onclick="batchRemove()">
                                <i class="fa fa-trash" aria-hidden="true"></i>删除
                            </button>
                        </div>
                        <table id="exampleTable" data-mobile-responsive="true">
                        </table>
                    </div>
                </div>
            </div>
            <!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
            <div>
                <script type="text/javascript">
                    var s_add_h = 'hidden';
                    var s_edit_h = 'hidden';
                    var s_remove_h = 'hidden';
                </script>
            </div>
            <div shiro:hasPermission="sys:menu:add">
                <script type="text/javascript">
                    s_add_h = '';
                </script>
            </div>
            <div shiro:hasPermission="sys:user:edit">
                <script type="text/javascript">
                    s_edit_h = '';
                </script>
            </div>
            <div shiro:hasPermission="sys:user:remove">
                <script type="text/javascript">
                    var s_remove_h = '';
                </script>
            </div>
        </div>
        <div th:include="common/base_include::footer"></div>
        <script src="/static/bootstrap/bootstrap-table/jquery.treegrid.js"></script>
        <script src="/static/bootstrap/bootstrap-table/jquery.treegrid.bootstrap3.js"></script>
        <script src="/static/bootstrap/bootstrap-table/jquery.treegrid.extension.js"></script>
        <script type="javascript">
            var prefix = "/sys/menu";
            $(function(){
                alert(2);
                load();
            });
            function load() {
                alert(1)
                $('#exampleTable').bootstrapTreeTable({
                    id: 'menuId',
                    code: 'menuId',
                    parentCode: 'parentId',
                    type: "GET", // 请求数据的ajax类型
                    url: prefix + '/list', // 请求数据的ajax的url
                    ajaxParams: {sort: 'order_num'}, // 请求数据的ajax的data属性
                    expandColumn: '1',// 在哪一列上面显示展开按钮
                    striped: true, // 是否各行渐变色
                    bordered: true, // 是否显示边框
                    expandAll: false, // 是否全部展开
                    // toolbar : '#exampleToolbar',
                    columns: [
                        {
                            title: '编号',
                            field: 'menuId',
                            visible: false,
                            align: 'center',
                            valign: 'center',
                            width: '5%'
                        },
                        {
                            title: '名称',
                            valign: 'center',
                            field: 'name',
                            width: '20%'
                        },

                        {
                            title: '图标',
                            field: 'icon',
                            align: 'center',
                            valign: 'center',
                            width: '5%',
                            formatter: function (item, index) {
                                return item.icon == null ? ''
                                    : '<i class="' + item.icon
                                    + ' fa-lg"></i>';
                            }
                        },
                        {
                            title: '类型',
                            field: 'type',
                            align: 'center',
                            valign: 'center',
                            width: '10%',
                            formatter: function (item, index) {
                                if (item.type === 0) {
                                    return '<span class="label label-primary">目录</span>';
                                }
                                if (item.type === 1) {
                                    return '<span class="label label-success">菜单</span>';
                                }
                                if (item.type === 2) {
                                    return '<span class="label label-warning">按钮</span>';
                                }
                            }
                        },
                        {
                            title: '地址',
                            valign: 'center',
                            width: '20%',
                            field: 'url'
                        },
                        {
                            title: '权限标识',
                            valign: 'center',
                            width: '20%',
                            field: 'perms'
                        },
                        {
                            title: '操作',
                            field: 'id',
                            align: 'center',
                            valign: 'center',
                            formatter: function (item, index) {
                                var e = '<a class="btn btn-primary btn-sm '
                                    + s_edit_h
                                    + '" href="#" mce_href="#" title="编辑" onclick="edit(\''
                                    + item.menuId
                                    + '\')"><i class="fa fa-edit"></i></a> ';
                                var p = '<a class="btn btn-primary btn-sm '
                                    + s_add_h
                                    + '" href="#" mce_href="#" title="添加下级" onclick="add(\''
                                    + item.menuId
                                    + '\')"><i class="fa fa-plus"></i></a> ';
                                var d = '<a class="btn btn-warning btn-sm '
                                    + s_remove_h
                                    + '" href="#" title="删除"  mce_href="#" onclick="remove(\''
                                    + item.menuId
                                    + '\')"><i class="fa fa-remove"></i></a> ';
                                return e + d + p;
                            }
                        }]
                });
            }

            function add(pId) {
                layer.open({
                    type: 2,
                    title: '增加菜单',
                    maxmin: true,
                    shadeClose: false, // 点击遮罩关闭层
                    area: ['800px', '500px'],
                    content: prefix + '/add/' + pId // iframe的url
                });
            }
        </script>
    </body>

</html>